package com.disruptor.sample._02producer.procucer;

import com.disruptor.sample.common.dto.LongEvent;
import com.lmax.disruptor.EventTranslatorOneArg;
import com.lmax.disruptor.RingBuffer;
import java.nio.ByteBuffer;

public class LongEventProducerPrevious3Version {

  private final RingBuffer<LongEvent> ringBuffer;

  public LongEventProducerPrevious3Version(RingBuffer<LongEvent> ringBuffer) {
    this.ringBuffer = ringBuffer;
  }

  private static final EventTranslatorOneArg<LongEvent, ByteBuffer> TRANSLATOR =
      new EventTranslatorOneArg<LongEvent, ByteBuffer>() {
        @Override
        public void translateTo(LongEvent event, long sequence, ByteBuffer bb) {
          event.setValue(bb.getLong(0));
        }
      };

  public void onData(ByteBuffer byteBuffer) {
    ringBuffer.publishEvent(TRANSLATOR, byteBuffer);
  }
}
